#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul  3 13:55:50 2023

@author: jcfq2
"""

import numpy as np
from scipy.spatial import Delaunay

from scipy.interpolate import NearestNDInterpolator
from scipy.interpolate import LinearNDInterpolator
import numpy as np

import matplotlib.pyplot as plt


def data_atlatlong(data,datalat,datalon,newlat,newlon,smooth=False):


    if smooth: 
        interp = LinearNDInterpolator(list(zip(datalon, datalat)), data)
    else:
        interp = NearestNDInterpolator(list(zip(datalon, datalat)), data)

    newdata = interp(newlon, newlat)

    return newdata
    
    
# rng = np.random.default_rng()

# datalon = rng.random(10) - 0.5

# datalat = rng.random(10) - 0.5

# data = rng.random(10)*10

# XX = np.linspace(min(datalon), max(datalon))

# YY = np.linspace(min(datalat), max(datalat))

# X, Y = np.meshgrid(XX, YY)  # 2D grid for interpolation

# newlat=Y
# newlon=X



#  use these to make work
# Z = data_atlatlong(data,datalat,datalon,newlat,newlon,smooth=True)
# ZZ = data_atlatlong(data,datalat,datalon,0,0,smooth=True)


# print(ZZ)
# plt.pcolormesh(X, Y, Z, shading='auto')

# plt.plot(datalon, datalat, "ok", label="input point")

# plt.legend()

# plt.colorbar()

# plt.axis("equal")

# plt.show()